package com.hubu.parking.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hubu.parking.common.BaseResponse;
import com.hubu.parking.common.DeleteRequest;
import com.hubu.parking.common.ResultUtils;
import com.hubu.parking.entity.sys.SysConfig;
import com.hubu.parking.model.dto.park.PageListConfigRequest;
import com.hubu.parking.service.SysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 实际停车记录接口
 */
@RestController
@RequestMapping("/config")
@Slf4j
public class ConfigController {
    @Resource
    private SysConfigService sysConfigService;

    /**
     * 查询
     *
     * @return
     */
    @PostMapping("/list")
    public BaseResponse<Page<SysConfig>> listConfig(@RequestBody PageListConfigRequest pageRequest) {
        return ResultUtils.success(sysConfigService.pageListConfigRecord(pageRequest));
    }

    /**
     * 新增/修改公告
     *
     * @param sysConfig 公告
     * @return
     */
    @PostMapping("saveOrUpdate")
    public BaseResponse<Boolean> add(@RequestBody SysConfig sysConfig) {
        boolean save = sysConfigService.saveOrUpdate(sysConfig);
        return ResultUtils.success(save);
    }

    /**
     * 删除
     *
     * @param deleteRequest
     * @return
     */
    @PostMapping("delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        Integer deleteId = deleteRequest.getId();
        boolean b = sysConfigService.removeById(deleteId);
        return ResultUtils.success(b);
    }

}
